const app = getApp()
Page({
  data: {
    name: '',
    uid: '',
    schoolname: '',
    copid: ''
  },

  onLoad: function (options) {
    var that = this;
    console.log(options.username)
    that.setData({
      schoolname: options.schoolname,
      copid: options.cop_id,
      name: options.name,
      uid: options.userid
    })
  },

  onReady: function () {

  },

  onShow: function () { },
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () { },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () { },

  unbind: function () {

    wx.showLoading({
      title: '解绑中',
    })
    var _this = this
    var data = {
      'open_id': wx.getStorageSync('openId'),
      'cop_id': this.data.copid,
      'uid': this.data.uid
    }

    app.post(app.globalData.serverurl + '/api/user/unbind', data).then((res) => {
      if (res.status == 'successful') {
        console.log(res)
        wx.showToast({
          title: '解绑成功',
          icon: 'loading',
          duration: 1000
        })
        wx.removeStorageSync('name'),
          wx.removeStorageSync('userId'),
          wx.removeStorageSync('cop_name'),
          wx.removeStorageSync('cop_id'),
          setTimeout(function () {
            wx.hideToast()
          }, 2000)
        wx.switchTab({
          url: '../../pages/index/index'
        })
      }
      else {
        wx.showModal({
          title: '解绑失败',
        })
      }
    })
  }

})